﻿#region
/*******************************************************************************
** File Name:		    AdminGroupRightService.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using Phoenix.Service.Contracts;
using Phoenix.Service.Model;
using Phoenix.IBatisRepository;
using Phoenix.Respository;
using System.Data;
using Phoenix.Entity;

namespace Phoenix.Service
{
    public class AdminGroupRightService : IAdminGroupRightService 
    {
		 IAdminGroupRight adminGroupRight = new AdminGroupRightRepository();
		 
		 #region  Auto Generation
		 
        public void AddAdminGroupRight(AdminGroupRightModel model)
        {
			EAdminGroupRight entity = ConvertModelToEntity(model);
			
            adminGroupRight.AddAdminGroupRight(entity);
        }

		public void UpdateByAdminGroupRightID (AdminGroupRightModel model)
		{
			EAdminGroupRight entity = ConvertModelToEntity(model);

            adminGroupRight.UpdateByAdminGroupRightID(entity);

		}

		public void DeleteByAdminGroupRightID (System.Int32 adminGroupRightID)
		{
		
            adminGroupRight.DeleteByAdminGroupRightID(adminGroupRightID);

		}
		 
        public AdminGroupRightModel GetByAdminGroupRightID (System.Int32 adminGroupRightID)
        {
        
			EAdminGroupRight entity = adminGroupRight.GetByAdminGroupRightID(adminGroupRightID);
			
            AdminGroupRightModel model = ConvertEntityToModel(entity);


            return model;
        }
        
		public AdminGroupRightModel ConvertEntityToModel(EAdminGroupRight entity)
		{
			if (entity == null)
            {
                return null;
            }
			AdminGroupRightModel model = new AdminGroupRightModel();
                        model.AdminGroupRightID = entity.AdminGroupRightID;
                        model.GroupID = entity.GroupID;
                        model.RightID = entity.RightID;
                        return model;
		}
		
		public EAdminGroupRight ConvertModelToEntity(AdminGroupRightModel model)
		{
			if (model == null)
            {
                return null;
            }
			EAdminGroupRight entity = new EAdminGroupRight();
                        entity.AdminGroupRightID = model.AdminGroupRightID;
                        entity.GroupID = model.GroupID;
                        entity.RightID = model.RightID;
                        return entity;
		}
		
		#endregion

        public AdminGroupRightModel GetByGroupIDAndRightID(int groupID, int rightID)
        {
            EAdminGroupRight entity = adminGroupRight.GetByGroupIDAndRightID(groupID, rightID);

            AdminGroupRightModel model = ConvertEntityToModel(entity);

            return model;
        }

        public IList<AdminGroupRightModel> GetByGroupID(int groupID)
        {
            IList<EAdminGroupRight> entityList = adminGroupRight.GetByGroupID(groupID);
            if (entityList == null)
                return null;

            IList<AdminGroupRightModel> modelList = new List<AdminGroupRightModel>();

            foreach (var item in entityList)
            {
                modelList.Add(ConvertEntityToModel(item));
            }
            return modelList;
        }

		public Dictionary<int, int> GetRightIDs(int groupID)
		{
			
			IList<EAdminGroupRight> entityList = adminGroupRight.GetByGroupID(groupID);
			if (entityList == null)
				return null;
			Dictionary<int, int> dic = new Dictionary<int, int>();

			foreach (var item in entityList)
			{
				dic.Add(item.RightID, 1);
			}

			return dic;

		}
    }
}